const {contextBridge,ipcRenderer} = require('electron')


const alert = (msg,type) => {
    ipcRenderer.invoke('on-alert-event', msg,type)
}
const openFile = () => {
    ipcRenderer.invoke('on-openFile-event')
}

const saveFile = async () => {
    const fileName = await ipcRenderer.invoke('on-savefile-event')
    return fileName
}

const saveJsonFile = async (args) => {
    const fileName = await ipcRenderer.invoke('on-savejsonfile-event',args)
    return fileName
}

const getDatabases = async () => {
    const data = await ipcRenderer.invoke('on-getDatabases-event')
    return data
}

const getPaper =  (filename) => {
    const data =  ipcRenderer.invoke('on-getpaper-event',filename)
    return data
}

const saveExamData = async (filename,examData) => {
    await ipcRenderer.invoke('on-saveexam-event',filename,examData)

}

const makeFile = async (filename) => {
    await ipcRenderer.invoke('on-makefile-event',filename)
}

const deleteExamData = async (filename,examdata) => {
    await ipcRenderer.invoke('on-deleteexamdata-event',filename,examdata)
}

const updateJsonFile =  (filename,data) => {
     ipcRenderer.invoke('on-updatejsonfile-event',filename,data)
}


contextBridge.exposeInMainWorld('myApi', {
    alert,
    openFile,
    saveFile,
    saveJsonFile,
    getDatabases,
    getPaper,
    saveExamData,
    makeFile,
    deleteExamData,
    updateJsonFile
})